{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}/Users/Allan/Dropbox/1Papers/1Reputation/Honor-Culture-War/2012-05/Replication-Final/2-150317-Data-Merge/2-150317-data-merge-log.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}30 Jun 2015, 16:02:23

{com}. 
. **** Load MID 4.01B data, downloaded from 

. **** http://www.correlatesofwar.org/data-sets/MIDs

. import delimited "1-Original-Data/MIDB_4.01-2.csv"
{res}{text}(21 vars, 6132 obs)
{com}. 
. ** Drop MIDs not involving the US

. keep if ccode==2
{txt}(5760 observations deleted)

{com}. 
. sort dispnum3 dispnum4 ccode

. save "1-Original-Data/MIDB-US.dta", replace
{txt}file 1-Original-Data/MIDB-US.dta saved

{com}. 
. 
. **** Load MID 4.01A data

. clear

. import delimited "1-Original-Data/MID-level/MIDA_4.01.csv"
{res}{text}(24 vars, 2586 obs)
{com}. sort dispnum3 dispnum4

. save "1-Original-Data/MIDA.dta", replace
{txt}file 1-Original-Data/MIDA.dta saved

{com}. 
. 
. **** Merge MIDB and MIDA data

. clear

. use "1-Original-Data/MIDB-US.dta"

. merge 1:1 dispnum3 dispnum4 using "1-Original-Data/MIDA.dta", gen(mergeid)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           2,214
{txt}{col 9}from master{col 30}{res}               0{txt}  (mergeid==1)
{col 9}from using{col 30}{res}           2,214{txt}  (mergeid==2)

{col 5}matched{col 30}{res}             372{txt}  (mergeid==3)
{col 5}{hline 41}

{com}. 
. keep if mergeid==3
{txt}(2214 observations deleted)

{com}. drop mergeid

. 
. ** Generating start and end dates

. gen StartDateUS = mdy(stmon, stday, styear) 
{txt}(43 missing values generated)

{com}. gen EndDateUS = mdy(endmon, endday, endyear)
{txt}(45 missing values generated)

{com}. 
. ** Some missing values due to missing stday or endday. 

. ** If MID started or ended in the same month, then impute missing day to the same day.

. replace StartDateUS = mdy(stmon, endday, styear) if StartDateUS==. & stmon==endmon & styear==endyear
{txt}(0 real changes made)

{com}. replace EndDateUS = mdy(endmon, stday, endyear) if EndDateUS==. & stmon==endmon & styear==endyear
{txt}(3 real changes made)

{com}. 
. ** Impute missing days with the 15th (an approximation)

. replace StartDateUS = mdy(stmon, 15, styear) if StartDateUS==.  
{txt}(43 real changes made)

{com}. replace EndDateUS = mdy(endmon, 15, endyear) if EndDateUS==.
{txt}(42 real changes made)

{com}. 
. format StartDateUS EndDateUS %td 

. order StartDateUS EndDateUS

. 
. gen LngthMIDUS = EndDateUS - StartDateUS + 1

. 
. 
. **** Assigning Outcome

. rename outcome outcomeMID
{res}
{com}. gen outcome = .
{txt}(372 missing values generated)

{com}. 
. ** outcome = 1 if US has Victory or other side Yields

. replace outcome = 1 if sidea==1 & (outcomeMID==1 | outcomeMID==4)
{txt}(45 real changes made)

{com}. replace outcome = 1 if sidea==0 & (outcomeMID==2 | outcomeMID==3)
{txt}(15 real changes made)

{com}. 
. ** outcome = -1 if other has Victory or US Yields

. replace outcome = -1 if sidea==1 & (outcomeMID==2 | outcomeMID==3)
{txt}(7 real changes made)

{com}. replace outcome = -1 if sidea==0 & (outcomeMID==1 | outcomeMID==4)
{txt}(4 real changes made)

{com}. 
. ** outcome = 0 if other coding

. replace outcome = 0 if outcomeMID>4 | outcomeMID==. | outcomeMID < 0
{txt}(301 real changes made)

{com}. 
. ** Indicator for whether the US used force in the MID

. gen ForceUS = 0

. replace ForceUS = 1 if hostlev >= 4      
{txt}(126 real changes made)

{com}. 
. ** Ordering Variables: date, outcome variables, treatment, controls

. order StartDateUS EndDateUS outcome fatality LngthMIDUS ForceUS

. 
. 
. **** Generate President variables

. gen Pres1 = ""
{txt}(372 missing values generated)

{com}. order Pres1 EndDateUS StartDateUS

. 
. sort StartDateUS dispnum3 dispnum4

. 
. ** Assign presidents to MIDs

. replace Pres1 = "Madison" if StartDateUS>=mdy(03, 04, 1809) & EndDateUS<mdy(03, 04, 1817)
{txt}Pres1 was {res}str1{txt} now {res}str7
{txt}(1 real change made)

{com}. replace Pres1 = "Monroe"  if StartDateUS>=mdy(03, 04, 1817) & EndDateUS<mdy(03, 04, 1825)
{txt}(6 real changes made)

{com}. replace Pres1 = "AdamsJQ" if StartDateUS>=mdy(03, 04, 1825) & EndDateUS<mdy(03, 04, 1829)
{txt}(1 real change made)

{com}. replace Pres1 = "Jackson" if StartDateUS>=mdy(03, 04, 1829) & EndDateUS<mdy(03, 04, 1837)
{txt}(3 real changes made)

{com}. replace Pres1 = "Van_Buren" if StartDateUS>=mdy(03, 04, 1837) & EndDateUS<mdy(03, 04, 1841)
{txt}Pres1 was {res}str7{txt} now {res}str9
{txt}(4 real changes made)

{com}. replace Pres1 = "HarrisonWH" if StartDateUS>=mdy(03, 04, 1841) & EndDateUS<mdy(04, 04, 1841)
{txt}(0 real changes made)

{com}. replace Pres1 = "Tyler" if StartDateUS>=mdy(04, 04, 1841) & EndDateUS<mdy(03, 04, 1845)
{txt}(1 real change made)

{com}. replace Pres1 = "Polk" if StartDateUS>=mdy(03, 04, 1845) & EndDateUS<mdy(03, 04, 1849)
{txt}(1 real change made)

{com}. replace Pres1 = "Taylor" if StartDateUS>=mdy(03, 04, 1849) & EndDateUS<mdy(03, 09, 1850)
{txt}(0 real changes made)

{com}. replace Pres1 = "Fillmore" if StartDateUS>=mdy(03, 09, 1850) & EndDateUS<mdy(03, 04, 1853)
{txt}(3 real changes made)

{com}. replace Pres1 = "Pierce" if StartDateUS>=mdy(03, 04, 1853) & EndDateUS<mdy(03, 04, 1857)
{txt}(7 real changes made)

{com}. replace Pres1 = "Buchanan" if StartDateUS>=mdy(03, 04, 1857) & EndDateUS<mdy(03, 04, 1861)
{txt}(6 real changes made)

{com}. replace Pres1 = "Lincoln" if StartDateUS>=mdy(03, 04, 1861) & EndDateUS<mdy(04, 15, 1865)
{txt}(5 real changes made)

{com}. replace Pres1 = "JohnsonA" if StartDateUS>=mdy(04, 15, 1865) & EndDateUS<mdy(03, 04, 1869)
{txt}(5 real changes made)

{com}. replace Pres1 = "Grant" if StartDateUS>=mdy(03, 04, 1869) & EndDateUS<mdy(03, 04, 1877)
{txt}(7 real changes made)

{com}. replace Pres1 = "Hayes" if StartDateUS>=mdy(03, 04, 1877) & EndDateUS<mdy(03, 04, 1881)
{txt}(3 real changes made)

{com}. replace Pres1 = "Garfield" if StartDateUS>=mdy(03, 04, 1881) & EndDateUS<mdy(09, 19, 1881)
{txt}(0 real changes made)

{com}. replace Pres1 = "Arthur" if StartDateUS>=mdy(09, 19, 1881) & EndDateUS<mdy(03, 04, 1885)
{txt}(2 real changes made)

{com}. replace Pres1 = "Cleveland1" if StartDateUS>=mdy(03, 04, 1885) & EndDateUS<mdy(03, 04, 1889)
{txt}Pres1 was {res}str9{txt} now {res}str10
{txt}(5 real changes made)

{com}. replace Pres1 = "HarrisonB" if StartDateUS>=mdy(03, 04, 1889) & EndDateUS<mdy(03, 04, 1893)
{txt}(3 real changes made)

{com}. replace Pres1 = "Cleveland2" if StartDateUS>=mdy(03, 04, 1893) & EndDateUS<mdy(03, 04, 1897)
{txt}(5 real changes made)

{com}. replace Pres1 = "McKinley" if StartDateUS>=mdy(03, 04, 1897) & EndDateUS<mdy(09, 14, 1901)
{txt}(3 real changes made)

{com}. replace Pres1 = "RooseveltT" if StartDateUS>=mdy(09, 14, 1901) & EndDateUS<mdy(03, 04, 1909)
{txt}(9 real changes made)

{com}. replace Pres1 = "Taft" if StartDateUS>=mdy(03, 04, 1909) & EndDateUS<mdy(03, 04, 1913)
{txt}(5 real changes made)

{com}. replace Pres1 = "Wilson" if StartDateUS>=mdy(03, 04, 1913) & EndDateUS<mdy(03, 04, 1921)
{txt}(18 real changes made)

{com}. replace Pres1 = "Harding" if StartDateUS>=mdy(03, 04, 1921) & EndDateUS<mdy(08, 02, 1923)
{txt}(1 real change made)

{com}. replace Pres1 = "Coolidge" if StartDateUS>=mdy(08, 02, 1923) & EndDateUS<mdy(03, 04, 1929)
{txt}(3 real changes made)

{com}. replace Pres1 = "Hoover" if StartDateUS>=mdy(03, 04, 1929) & EndDateUS<mdy(03, 04, 1933)
{txt}(2 real changes made)

{com}. replace Pres1 = "RooseveltFD" if StartDateUS>=mdy(03, 04, 1933) & EndDateUS<mdy(04, 12, 1945)
{txt}Pres1 was {res}str10{txt} now {res}str11
{txt}(11 real changes made)

{com}. replace Pres1 = "Truman" if StartDateUS>=mdy(04, 12, 1945) & EndDateUS<mdy(01, 20, 1953)
{txt}(9 real changes made)

{com}. replace Pres1 = "Eisenhower" if StartDateUS>=mdy(01, 20, 1953) & EndDateUS<mdy(01, 20, 1961)
{txt}(33 real changes made)

{com}. replace Pres1 = "Kennedy" if StartDateUS>=mdy(01, 20, 1961) & EndDateUS<mdy(11, 22, 1963)
{txt}(14 real changes made)

{com}. replace Pres1 = "JohnsonLB" if StartDateUS>=mdy(11, 22, 1963) & EndDateUS<mdy(01, 20, 1969)
{txt}(21 real changes made)

{com}. replace Pres1 = "Nixon" if StartDateUS>=mdy(01, 20, 1969) & EndDateUS<mdy(08, 09, 1974)
{txt}(16 real changes made)

{com}. replace Pres1 = "Ford" if StartDateUS>=mdy(08, 09, 1974) & EndDateUS<mdy(01, 20, 1977)
{txt}(10 real changes made)

{com}. replace Pres1 = "Carter" if StartDateUS>=mdy(01, 20, 1977) & EndDateUS<mdy(01, 20, 1981)
{txt}(12 real changes made)

{com}. replace Pres1 = "Reagan" if StartDateUS>=mdy(01, 20, 1981) & EndDateUS<mdy(01, 20, 1989)
{txt}(43 real changes made)

{com}. replace Pres1 = "BushGHW" if StartDateUS>=mdy(01, 20, 1989) & EndDateUS<mdy(01, 20, 1993)
{txt}(8 real changes made)

{com}. replace Pres1 = "Clinton" if StartDateUS>=mdy(01, 20, 1993) & EndDateUS<mdy(01, 20, 2001)
{txt}(31 real changes made)

{com}. replace Pres1 = "BushGW" if StartDateUS>=mdy(01, 20, 2001) & EndDateUS<mdy(01, 20, 2009)
{txt}(25 real changes made)

{com}. replace Pres1 = "Obama" if StartDateUS>=mdy(01, 20, 2009) & EndDateUS<mdy(03, 13, 2015)
{txt}(5 real changes made)

{com}. 
. ** Note: Some MIDs spillover across Presidencies

. generate spillover = 0

. replace spillover = 1 if Pres1==""
{txt}(25 real changes made)

{com}. 
. ** Assigning spillover MIDs to first President to experience MID

. replace Pres1 = "Madison" if StartDateUS>=mdy(03, 04, 1809) & spillover==1
{txt}(25 real changes made)

{com}. replace Pres1 = "Monroe"  if StartDateUS>=mdy(03, 04, 1817) & spillover==1
{txt}(25 real changes made)

{com}. replace Pres1 = "AdamsJQ" if StartDateUS>=mdy(03, 04, 1825) & spillover==1
{txt}(25 real changes made)

{com}. replace Pres1 = "Jackson" if StartDateUS>=mdy(03, 04, 1829) & spillover==1
{txt}(25 real changes made)

{com}. replace Pres1 = "Van_Buren" if StartDateUS>=mdy(03, 04, 1837) & spillover==1
{txt}(24 real changes made)

{com}. replace Pres1 = "HarrisonWH" if StartDateUS>=mdy(03, 04, 1841) & spillover==1
{txt}(24 real changes made)

{com}. replace Pres1 = "Tyler" if StartDateUS>=mdy(04, 04, 1841) & spillover==1
{txt}(24 real changes made)

{com}. replace Pres1 = "Polk" if StartDateUS>=mdy(03, 04, 1845) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "Taylor" if StartDateUS>=mdy(03, 04, 1849) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "Fillmore" if StartDateUS>=mdy(03, 09, 1850) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "Pierce" if StartDateUS>=mdy(03, 04, 1853) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "Buchanan" if StartDateUS>=mdy(03, 04, 1857) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "Lincoln" if StartDateUS>=mdy(03, 04, 1861) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "JohnsonA" if StartDateUS>=mdy(04, 15, 1865) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "Grant" if StartDateUS>=mdy(03, 04, 1869) & spillover==1
{txt}(23 real changes made)

{com}. replace Pres1 = "Hayes" if StartDateUS>=mdy(03, 04, 1877) & spillover==1
{txt}(22 real changes made)

{com}. replace Pres1 = "Garfield" if StartDateUS>=mdy(03, 04, 1881) & spillover==1
{txt}(22 real changes made)

{com}. replace Pres1 = "Arthur" if StartDateUS>=mdy(09, 19, 1881) & spillover==1
{txt}(22 real changes made)

{com}. replace Pres1 = "Cleveland1" if StartDateUS>=mdy(03, 04, 1885) & spillover==1
{txt}(22 real changes made)

{com}. replace Pres1 = "HarrisonB" if StartDateUS>=mdy(03, 04, 1897) & spillover==1
{txt}(21 real changes made)

{com}. replace Pres1 = "Cleveland2" if StartDateUS>=mdy(03, 04, 1893) & spillover==1
{txt}(21 real changes made)

{com}. replace Pres1 = "McKinley" if StartDateUS>=mdy(03, 04, 1897) & spillover==1
{txt}(21 real changes made)

{com}. replace Pres1 = "RooseveltT" if StartDateUS>=mdy(09, 14, 1901) & spillover==1
{txt}(21 real changes made)

{com}. replace Pres1 = "Taft" if StartDateUS>=mdy(03, 04, 1909) & spillover==1
{txt}(20 real changes made)

{com}. replace Pres1 = "Wilson" if StartDateUS>=mdy(03, 04, 1913) & spillover==1
{txt}(20 real changes made)

{com}. replace Pres1 = "Harding" if StartDateUS>=mdy(03, 04, 1921) & spillover==1
{txt}(19 real changes made)

{com}. replace Pres1 = "Coolidge" if StartDateUS>=mdy(08, 02, 1923) & spillover==1
{txt}(19 real changes made)

{com}. replace Pres1 = "Hoover" if StartDateUS>=mdy(03, 04, 1929) & spillover==1
{txt}(19 real changes made)

{com}. replace Pres1 = "RooseveltFD" if StartDateUS>=mdy(03, 04, 1933) & spillover==1
{txt}(19 real changes made)

{com}. replace Pres1 = "Truman" if StartDateUS>=mdy(04, 12, 1945) & spillover==1
{txt}(18 real changes made)

{com}. replace Pres1 = "Eisenhower" if StartDateUS>=mdy(01, 20, 1953) & spillover==1
{txt}(17 real changes made)

{com}. replace Pres1 = "Kennedy" if StartDateUS>=mdy(01, 20, 1961) & spillover==1
{txt}(14 real changes made)

{com}. replace Pres1 = "JohnsonLB" if StartDateUS>=mdy(11, 22, 1963) & spillover==1
{txt}(12 real changes made)

{com}. replace Pres1 = "Nixon" if StartDateUS>=mdy(01, 20, 1969) & spillover==1
{txt}(9 real changes made)

{com}. replace Pres1 = "Ford" if StartDateUS>=mdy(08, 09, 1974) & spillover==1
{txt}(9 real changes made)

{com}. replace Pres1 = "Carter" if StartDateUS>=mdy(01, 20, 1977) & spillover==1
{txt}(9 real changes made)

{com}. replace Pres1 = "Reagan" if StartDateUS>=mdy(01, 20, 1981) & spillover==1
{txt}(7 real changes made)

{com}. replace Pres1 = "BushGHW" if StartDateUS>=mdy(01, 20, 1989) & spillover==1
{txt}(6 real changes made)

{com}. replace Pres1 = "Clinton" if StartDateUS>=mdy(01, 20, 1993) & spillover==1
{txt}(3 real changes made)

{com}. replace Pres1 = "BushGW" if StartDateUS>=mdy(01, 20, 2001) & spillover==1
{txt}(2 real changes made)

{com}. replace Pres1 = "Obama" if StartDateUS>=mdy(01, 20, 2009) & spillover==1
{txt}(0 real changes made)

{com}. 
. 
. ** Variable for the name of the President who was the first to inherit the MID

. gen Pres2 = ""
{txt}(372 missing values generated)

{com}. replace Pres2 = "Obama" if spillover==1 & EndDateUS<mdy(01, 20, 2013)
{txt}Pres2 was {res}str1{txt} now {res}str5
{txt}(25 real changes made)

{com}. replace Pres2 = "BushGW" if spillover==1 & EndDateUS<mdy(01, 20, 2009)
{txt}Pres2 was {res}str5{txt} now {res}str6
{txt}(23 real changes made)

{com}. replace Pres2 = "Clinton" if spillover==1 & EndDateUS<mdy(01, 20, 2001)
{txt}Pres2 was {res}str6{txt} now {res}str7
{txt}(22 real changes made)

{com}. replace Pres2 = "BushGHW" if spillover==1 & EndDateUS<mdy(01, 20, 1993)
{txt}(19 real changes made)

{com}. replace Pres2 = "Reagan" if spillover==1 & EndDateUS<mdy(01, 20, 1989)
{txt}(18 real changes made)

{com}. replace Pres2 = "Carter" if spillover==1 & EndDateUS<mdy(01, 20, 1981)
{txt}(16 real changes made)

{com}. replace Pres2 = "Ford" if spillover==1 & EndDateUS<mdy(01, 20, 1977)
{txt}(16 real changes made)

{com}. replace Pres2 = "Nixon" if spillover==1 & EndDateUS<mdy(08, 09, 1974)
{txt}(16 real changes made)

{com}. replace Pres2 = "JohnsonLB" if spillover==1 & EndDateUS<mdy(01, 20, 1969)
{txt}Pres2 was {res}str7{txt} now {res}str9
{txt}(12 real changes made)

{com}. replace Pres2 = "Kennedy" if spillover==1 & EndDateUS<mdy(11, 22, 1963)
{txt}(11 real changes made)

{com}. replace Pres2 = "Eisenhower" if spillover==1 & EndDateUS<mdy(01, 20, 1961)
{txt}Pres2 was {res}str9{txt} now {res}str10
{txt}(8 real changes made)

{com}. replace Pres2 = "Truman" if spillover==1 & EndDateUS<mdy(01, 20, 1953)
{txt}(7 real changes made)

{com}. replace Pres2 = "RooseveltFD" if spillover==1 & EndDateUS<mdy(04, 12, 1945)
{txt}Pres2 was {res}str10{txt} now {res}str11
{txt}(6 real changes made)

{com}. replace Pres2 = "Hoover" if spillover==1 & EndDateUS<mdy(03, 04, 1933)
{txt}(6 real changes made)

{com}. replace Pres2 = "Coolidge" if spillover==1 & EndDateUS<mdy(03, 04, 1929)
{txt}(6 real changes made)

{com}. replace Pres2 = "Harding" if spillover==1 & EndDateUS<mdy(08, 02, 1923)
{txt}(6 real changes made)

{com}. replace Pres2 = "Wilson" if spillover==1 & EndDateUS<mdy(03, 04, 1921)
{txt}(5 real changes made)

{com}. replace Pres2 = "Taft" if spillover==1 & EndDateUS<mdy(03, 04, 1913)
{txt}(5 real changes made)

{com}. replace Pres2 = "RooseveltT" if spillover==1 & EndDateUS<mdy(03, 04, 1909)
{txt}(4 real changes made)

{com}. replace Pres2 = "McKinley" if spillover==1 & EndDateUS<mdy(09, 14, 1901)
{txt}(4 real changes made)

{com}. replace Pres2 = "Cleveland2" if spillover==1 & EndDateUS<mdy(03, 04, 1897)
{txt}(4 real changes made)

{com}. replace Pres2 = "HarrisonB" if spillover==1 & EndDateUS<mdy(03, 04, 1893)
{txt}(4 real changes made)

{com}. replace Pres2 = "Cleveland1" if spillover==1 & EndDateUS<mdy(03, 04, 1889)
{txt}(3 real changes made)

{com}. replace Pres2 = "Arthur" if spillover==1 & EndDateUS<mdy(03, 04, 1885)
{txt}(3 real changes made)

{com}. replace Pres2 = "Garfield" if spillover==1 & EndDateUS<mdy(09, 19, 1881)
{txt}(3 real changes made)

{com}. replace Pres2 = "Hayes" if spillover==1 & EndDateUS<mdy(03, 04, 1881)
{txt}(3 real changes made)

{com}. replace Pres2 = "Grant" if spillover==1 & EndDateUS<mdy(03, 04, 1877)
{txt}(2 real changes made)

{com}. replace Pres2 = "JohnsonA" if spillover==1 & EndDateUS<mdy(03, 04, 1869)
{txt}(2 real changes made)

{com}. replace Pres2 = "Lincoln" if spillover==1 & EndDateUS<mdy(04, 15, 1865)
{txt}(2 real changes made)

{com}. replace Pres2 = "Buchanan" if spillover==1& EndDateUS<mdy(03, 04, 1861)
{txt}(2 real changes made)

{com}. replace Pres2 = "Pierce" if spillover==1 & EndDateUS<mdy(03, 04, 1857)
{txt}(2 real changes made)

{com}. replace Pres2 = "Fillmore" if spillover==1 & EndDateUS<mdy(03, 04, 1853)
{txt}(2 real changes made)

{com}. replace Pres2 = "Taylor" if spillover==1 & EndDateUS<mdy(03, 09, 1850)
{txt}(2 real changes made)

{com}. replace Pres2 = "Polk" if spillover==1 & EndDateUS<mdy(03, 04, 1849)
{txt}(2 real changes made)

{com}. replace Pres2 = "Tyler" if spillover==1 & EndDateUS<mdy(03, 04, 1845)
{txt}(1 real change made)

{com}. replace Pres2 = "HarrisonWH" if spillover==1 & EndDateUS<mdy(04, 04, 1841)
{txt}(1 real change made)

{com}. replace Pres2 = "Van_Buren" if spillover==1 & EndDateUS<mdy(03, 04, 1841)
{txt}(1 real change made)

{com}. replace Pres2 = "Jackson" if spillover==1 & EndDateUS<mdy(03, 04, 1837)
{txt}(0 real changes made)

{com}. replace Pres2 = "Quincy_Adams" if spillover==1 & EndDateUS<mdy(03, 04, 1829)
{txt}(0 real changes made)

{com}. replace Pres2 = "Monroe"  if spillover==1 & EndDateUS<mdy(03, 04, 1825)
{txt}(0 real changes made)

{com}. replace Pres2 = "Madison" if spillover==1 & EndDateUS<mdy(03, 04, 1817)
{txt}(0 real changes made)

{com}. 
. ** Merge with US presidents data using variable `varname'

. 
. gen varname=Pres1   

. sort varname

. 
. ** see presidentnames.xlsx for code for next section

. replace varname="madison" if varname=="Madison"
{txt}(1 real change made)

{com}. replace varname="monroe" if varname=="Monroe"
{txt}(6 real changes made)

{com}. replace varname="adams2" if varname=="AdamsJQ"
{txt}(1 real change made)

{com}. replace varname="jackson" if varname=="Jackson"
{txt}(4 real changes made)

{com}. replace varname="van_buren" if varname=="Van_Buren"
{txt}(4 real changes made)

{com}. replace varname="harrison1" if varname=="HarrisonWH"
{txt}(0 real changes made)

{com}. replace varname="tyler" if varname=="Tyler"
{txt}(2 real changes made)

{com}. replace varname="polk" if varname=="Polk"
{txt}(1 real change made)

{com}. replace varname="taylor" if varname=="Taylor"
{txt}(0 real changes made)

{com}. replace varname="fillmore" if varname=="Fillmore"
{txt}(3 real changes made)

{com}. replace varname="pierce" if varname=="Pierce"
{txt}(7 real changes made)

{com}. replace varname="buchanan" if varname=="Buchanan"
{txt}(6 real changes made)

{com}. replace varname="lincoln" if varname=="Lincoln"
{txt}(5 real changes made)

{com}. replace varname="johnson1" if varname=="JohnsonA"
{txt}(5 real changes made)

{com}. replace varname="grant" if varname=="Grant"
{txt}(8 real changes made)

{com}. replace varname="hayes" if varname=="Hayes"
{txt}(3 real changes made)

{com}. replace varname="garfield" if varname=="Garfield"
{txt}(0 real changes made)

{com}. replace varname="arthur" if varname=="Arthur"
{txt}(2 real changes made)

{com}. replace varname="cleveland" if varname=="Cleveland1"
{txt}(6 real changes made)

{com}. replace varname="harrison2" if varname=="HarrisonB"
{txt}(3 real changes made)

{com}. replace varname="cleveland2" if varname=="Cleveland2"
{txt}(5 real changes made)

{com}. replace varname="mckinley" if varname=="McKinley"
{txt}(3 real changes made)

{com}. replace varname="roosevelt1" if varname=="RooseveltT"
{txt}(10 real changes made)

{com}. replace varname="taft" if varname=="Taft"
{txt}(5 real changes made)

{com}. replace varname="wilson" if varname=="Wilson"
{txt}(19 real changes made)

{com}. replace varname="harding" if varname=="Harding"
{txt}(1 real change made)

{com}. replace varname="coolidge" if varname=="Coolidge"
{txt}(3 real changes made)

{com}. replace varname="hoover" if varname=="Hoover"
{txt}(2 real changes made)

{com}. replace varname="roosevelt2" if varname=="RooseveltFD"
{txt}(12 real changes made)

{com}. replace varname="truman" if varname=="Truman"
{txt}(10 real changes made)

{com}. replace varname="eisenhower" if varname=="Eisenhower"
{txt}(36 real changes made)

{com}. replace varname="kennedy" if varname=="Kennedy"
{txt}(16 real changes made)

{com}. replace varname="johnson2" if varname=="JohnsonLB"
{txt}(24 real changes made)

{com}. replace varname="nixon" if varname=="Nixon"
{txt}(16 real changes made)

{com}. replace varname="ford" if varname=="Ford"
{txt}(10 real changes made)

{com}. replace varname="carter" if varname=="Carter"
{txt}(14 real changes made)

{com}. replace varname="reagan" if varname=="Reagan"
{txt}(44 real changes made)

{com}. replace varname="bush1" if varname=="BushGHW"
{txt}(11 real changes made)

{com}. replace varname="clinton" if varname=="Clinton"
{txt}(32 real changes made)

{com}. replace varname="bush2" if varname=="BushGW"
{txt}(27 real changes made)

{com}. replace varname="obama" if varname=="Obama"
{txt}(5 real changes made)

{com}. 
. sort varname

. merge m:1 varname using "1-Original-Data/USPres2010-10-13.dta"                                         
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               6
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}               6{txt}  (_merge==2)

{col 5}matched{col 30}{res}             372{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
         using only (2) {c |}{res}          6        1.59        1.59
{txt}            matched (3) {c |}{res}        372       98.41      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}        378      100.00

{com}. order _merge

. ** Dropping Presidents not in the MID dataset

. drop if _merge==2
{txt}(6 observations deleted)

{com}. drop _merge

. sort StartDateUS dispnum3 dispnum4

. 
. ** Counting number of bilateral disputes

. *"those involving the United States and only one other country"

. count if numa==1 & numb==1
{res}  235

{com}. 
. ** Counting number of disputes with the US as an originator

. *"report the results for multiparty disputes in which the United States was an originator to the dispute"

. count if orig==1
{res}  316

{com}. 
. save "3-Analysis-Data/15-03-13-merging.dta", replace
{txt}file 3-Analysis-Data/15-03-13-merging.dta saved

{com}. 
. ** The following do files finish the merging process, each producing a separate dataset with a different coding of Southernness

. 
. **Main coding, Truman not Southern, GWBush Southern

. do "2-150317-Data-Merge/2-150317-data-merge1.do"
{txt}
{com}. **Code produced in 2015-03-13 by Allan Dafoe and Devin Caughey
. 
. clear
{txt}
{com}. use "3-Analysis-Data/15-03-13-merging.dta"
{txt}
{com}. 
. ** Indicator for Southern origin of Pres1 (under which MID started)
. gen South1 = 0
{txt}
{com}. replace South1 = 1 if inlist(Pres1, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH")
{txt}(11 real changes made)

{com}. replace South1 = 1 if inlist(Pres1, "Tyler", "Polk", "Taylor", "JohnsonA", "Wilson", "JohnsonLB", "Carter", "Clinton", "BushGW")
{txt}(124 real changes made)

{com}. replace South1 = . if Pres1=="" 
{txt}(0 real changes made)

{com}. 
. 
. ** Indicator for Southern origin of Pres2 (who inherited the MID)
. gen South2 = 0
{txt}
{com}. order Pres2 South2
{txt}
{com}. replace South2 = 1 if inlist(Pres2, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH")
{txt}(0 real changes made)

{com}. replace South2 = 1 if inlist(Pres2, "Tyler", "Polk", "Taylor", "JohnsonA", "Wilson", "JohnsonLB", "Carter", "Clinton", "BushGW")
{txt}(6 real changes made)

{com}. replace South2 = . if Pres2=="" 
{txt}(347 real changes made, 347 to missing)

{com}. 
. 
. ** Start and end dates and length of presidents' terms
. gen TermStartDate = mdy(TermStartMonth, TermStartDay, TermStartYear)
{txt}
{com}. gen TermEndDate = mdy(TermEndMonth, TermEndDay, TermEndYear)  
{txt}(5 missing values generated)

{com}. 
. ** Assigning end of MID data as end of Term for Obama
. replace TermEndDate = mdy(12, 31, 2010) if Pres1=="Obama"
{txt}(5 real changes made)

{com}. replace TermStartDate = mdy(1, 1, 1816) if Pres1 == "Madison"
{txt}(1 real change made)

{com}. 
. format TermEndDate TermStartDate %td
{txt}
{com}. gen TermLength = TermEndDate - TermStartDate + 1 
{txt}
{com}. 
. ** Make Cleveland's term length be the sum of his two terms.
. tab TermLength if Pres1=="Cleveland1" | Pres1=="Cleveland2"

 {txt}TermLength {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
       1462 {c |}{res}         11      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}         11      100.00
{txt}
{com}. replace TermLength = 2* 1462 if Pres1=="Cleveland1" | Pres1=="Cleveland2"
{txt}(11 real changes made)

{com}. 
. order TermStartDate TermEndDate
{txt}
{com}. 
. *** Code to create variable proprec, which measures the proportion of the 
. *** President's term that experienced a recession
. ** daysrec is Days in Recession
. gen proprec = daysrec / TermLength
{txt}
{com}. 
. ** Days into Pres1's term that US involvement in the MID began/ended
. gen StrtDayInTrm1 = StartDateUS - TermStartDate
{txt}
{com}. rename TermStartDate TermStartDate1  
{res}{txt}
{com}. rename TermEndDate TermEndDate1               
{res}{txt}
{com}. 
. gen EndDayInTrm1 = EndDateUS - TermStartDate1
{txt}
{com}.                   
. gen DaysInTrm1 = LngthMIDUS
{txt}
{com}. replace DaysInTrm1 = TermEndDate1 - StartDateUS + 1 if Pres2!=""
{txt}(23 real changes made)

{com}. order StrtDayInTrm1 EndDayInTrm1
{txt}
{com}. 
. ** Indicator for the US being Originator of the dispute
. gen US_Init = orig
{txt}
{com}. 
. ** Indicator for US being the only nation on its side of the MID        
. gen US_alone = 0
{txt}
{com}. replace US_alone = 1 if sidea==1 & numa==1
{txt}(143 real changes made)

{com}. replace US_alone = 1 if sidea==0 & numb==1
{txt}(100 real changes made)

{com}. 
. ** Indicator for US's opponent being the only nation on its side
. gen opp_alone = 0
{txt}
{com}. replace opp_alone = 1 if sidea==1 & numb==1
{txt}(187 real changes made)

{com}. replace opp_alone = 1 if sidea==0 & numa==1
{txt}(151 real changes made)

{com}. 
. ** Indicator for both parties being the only nation on each's side
. gen BothAlone = US_alone*opp_alone
{txt}
{com}. 
. ** Index observations within each president, ordered by the date of US
. ** involvement, dispute number
. sort Pres1 StartDateUS dispnum3 dispnum4
{txt}
{com}. by Pres1: egen int PresOb = seq()
{txt}
{com}. sort StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Indicator for fishing disputes, from Cohen and Weeks
. gen FishDisp = 0
{txt}
{com}. replace FishDisp = 1 if dispnum3==1705 | dispnum3==3222 | dispnum3==2845 | dispnum3==3244 | dispnum3==1803 | dispnum3==1805 | dispnum3==350 | dispnum3==1158 | dispnum3==601 | dispnum3==602 | dispnum3==2952 | dispnum3==2954 | dispnum3==2953 | dispnum3==2958 | dispnum3==2222 | dispnum3==2968 | dispnum3==2967 | dispnum3==3972 | dispnum3==4183 | dispnum3==4174
{txt}(20 real changes made)

{com}. 
. ** Variable for number of opponents of US in MID
. gen nOpps = numb if sidea==1
{txt}(169 missing values generated)

{com}. replace nOpps = numa if sidea==0
{txt}(169 real changes made)

{com}. 
. *** Create placeholder observations for Presidents in whose terms no
. *** MIDs occurred
. set obs `=_N + 1'
{txt}obs was 372, now 373

{com}. replace Pres1 = "Washington" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 1 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(4, 30, 1789) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 373, now 374

{com}. replace Pres1 = "AdamsJ" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 2 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1801) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 374, now 375

{com}. replace Pres1 = "Jefferson" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 3 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1801) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1809) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l 
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 375, now 376

{com}. replace Pres1 = "HarrisonWH" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 9 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1841) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(4, 6, 1841) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 376, now 377

{com}. replace Pres1 = "Taylor" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 12 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 5, 1849) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(7, 10, 1850) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 377, now 378

{com}. replace Pres1 = "Garfield" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 20 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1881) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(9, 20, 1881) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Republican" in l
{txt}(1 real change made)

{com}. 
. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Create simpler version of party for first president
. gen Party1 = Party    
{txt}(3 missing values generated)

{com}. replace Party1 = "Democratic" if Party=="Democratic; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Republican" if Party=="Republican; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Whig" if Party=="Whig; None"
{txt}(2 real changes made)

{com}. replace Party1 = "Democratic-Republican" if  Party=="Democratic-Republican; National Republican"
{txt}(1 real change made)

{com}. encode Party1, generate (Party1Factor)
{txt}
{com}. 
. ** Labels for `outcome'
. label define outcome -1 "US Lose" 0 "Stalemate, Compromise, Released, Unclear, Join war, Missing" 1 "US Win"
{txt}
{com}. 
. label value outcome outcome
{txt}
{com}. 
. 
. ** Indicator for whether the US was an Originator in the dispute
. gen Primary = 0
{txt}
{com}. replace Primary = 1 if orig==1
{txt}(316 real changes made)

{com}. 
. ** Create label for `Order' that includes missing presidents
. label define PresOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 24 "Cleveland" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. gen Pres1Order = Order
{txt}
{com}. drop Order
{txt}
{com}. label values Pres1Order PresOrder 
{txt}
{com}. 
. ** Create cluster variable `Leader' that treats Cleveland's two terms 
. ** as one cluster
. generate Leader = Pres1Order
{txt}
{com}. replace Leader = 22 if Leader==24
{txt}(5 real changes made)

{com}. 
. ** Create label for `Leader' that includes missing presidents, but 
. ** Cleveland is only listed once.
. label define LeaderOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. label values Leader LeaderOrder 
{txt}
{com}. 
. generate Leader2 = .
{txt}(378 missing values generated)

{com}. replace Leader2 = Leader[_n] + 1 if Pres2!=""
{txt}(25 real changes made)

{com}. label values Leader2 LeaderOrder
{txt}
{com}. 
. ** Note: the only difference between `Leader' and `Pres1Order' is that 
. ** the two non-consecutive administrations of Grover Cleveland are 
. ** listed under the same number (22) in `Leader' but as different 
. ** numbers (22 and 24) in `Pres1Order'. 
.  
. ** Previous and next presidents
. gen PresPrev = Pres1Order - 1
{txt}
{com}. label values PresPrev PresOrder
{txt}
{com}. gen PresNext = Pres1Order + 1
{txt}
{com}. label values PresNext PresOrder
{txt}
{com}. replace PresPrev = . if PresPrev==0
{txt}(1 real change made, 1 to missing)

{com}. replace PresNext = . if PresPrev==45
{txt}(0 real changes made)

{com}. 
. sort Pres1Order StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort dispnum3 dispnum4
{txt}
{com}. by dispnum3 dispnum4: egen ObInDispute = seq()
{txt}
{com}. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort Leader StartDateUS dispnum3 dispnum4
{txt}
{com}. by Leader: egen int LeaderOb = seq()
{txt}
{com}. 
. ** Expressing Term Length in Years
. gen TermYrsAdj = TermLeng/365.25
{txt}
{com}. 
. 
. ** Number of MIDs of each Leader in each category
. by Leader, sort: egen nMIDs = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader, sort: egen nMIDsNoF = total(FishDisp==0)
{txt}
{com}. by Leader, sort: egen nMIDsPrim = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nMIDsAlone = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. by Leader, sort: egen nMIDsAloneTarg = total(FishDisp==0 & BothAlone==1 & sidea==0)
{txt}
{com}. by Leader, sort: egen nMIDsAloneInit = total(FishDisp==0 & BothAlone==1 & sidea==1)
{txt}
{com}. 
. ** Each Leader's number of MIDs per year
. gen nMIDsPerYr = nMIDs/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr = nMIDsNoF/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr = nMIDsPrim/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr = nMIDsAlone/TermYrsAdj
{txt}
{com}. gen nMIDsAloneTargPerYr = nMIDsAloneTarg/TermYrsAdj
{txt}
{com}. gen nMIDsAloneInitPerYr = nMIDsAloneInit/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader, sort: egen nForce = total(ForceUS==1)
{txt}
{com}. by Leader, sort: egen nForceNoF = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader, sort: egen nForcePrim = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nForceAlone = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr = nForce/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr = nForceNoF/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr = nForcePrim/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr = nForceAlone/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID = nForce/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF = nForceNoF/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim = nForcePrim/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone = nForceAlone/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. 
. ** Time variables
. gen TermStartDateSq = TermStartDate1^2
{txt}
{com}. gen TermStartDateCu = TermStartDate1^3
{txt}
{com}. gen Era = 1
{txt}
{com}. replace Era = 2 if Leader>=25 & Leader<33
{txt}(55 real changes made)

{com}. replace Era = 3 if Leader>=33
{txt}(245 real changes made)

{com}. label define Era 1 "pre-1897" 2 "1897-1945" 3 "post-1945"
{txt}
{com}. label values Era Era
{txt}
{com}. 
. ** Merge country-year data (this is a subset of Gelpi and 
. ** Feaver's data with one observation per year)
. ** Merging on MID Start Year
. gen year = styear
{txt}(6 missing values generated)

{com}. sort year
{txt}
{com}. merge m:1 year using "1-Original-Data/bigstickcountry-year.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             123
{txt}{col 9}from master{col 30}{res}              71{txt}  (_merge==1)
{col 9}from using{col 30}{res}              52{txt}  (_merge==2)

{col 5}matched{col 30}{res}             307{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}         71       16.51       16.51
{txt}         using only (2) {c |}{res}         52       12.09       28.60
{txt}            matched (3) {c |}{res}        307       71.40      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}        430      100.00
{txt}
{com}. sum year if _merge==1

{txt}    Variable {c |}       Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 56}
{space 8}year {c |}{res}        65    2000.908    5.011621       1993       2010
{txt}
{com}. ** G&F's data doesn't go beyond 1992.
. 
. ** _merge==2 are country-years when there was not a MID.
. drop if _merge==2
{txt}(52 observations deleted)

{com}. drop _merge
{txt}
{com}. 
. 
. sort Pres1Order StartDateUS
{txt}
{com}. 
. replace ObInDispute = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDs = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsPrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForce = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForcePrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. 
. *** Alternative assignment of MIDs to Leader2
. generate alt = .
{txt}(378 missing values generated)

{com}. replace alt = 0 if dispnum3!=.
{txt}(372 real changes made)

{com}. ** Mexican-American War (Tyler and Polk)
. replace alt = 1 if dispnum3==1552
{txt}(1 real change made)

{com}. ** 1958-61 dipute with North Korea (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==2187
{txt}(1 real change made)

{com}. ** Bay of Pigs Invasion (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==40
{txt}(0 real changes made)

{com}. ** 1963-64 dispute with North Korea (Kennedy and JohnsonLB)
. replace alt = 1 if dispnum3==2189
{txt}(1 real change made)

{com}. ** Cambodian Campaign (JohnsonLB and Nixon)
. replace alt = 1 if dispnum3==1806
{txt}(1 real change made)

{com}. ** Invasion of Panama (Reagan and BushGHW)                         
. replace alt = 1 if dispnum3==3901
{txt}(1 real change made)

{com}. ** Yugoslav wars (BushGHW and Clinton)
. replace alt = 1 if dispnum3==3551
{txt}(1 real change made)

{com}. 
. generate Leader_alt = Leader
{txt}
{com}. replace Leader_alt = Leader2 if alt==1
{txt}(6 real changes made)

{com}. label values Leader_alt LeaderOrder
{txt}
{com}. 
. ** Number of MIDs of each Leader_alt in each category
. by Leader_alt, sort: egen nMIDs_alt = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader_alt, sort: egen nMIDsNoF_alt = total(FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nMIDsPrim_alt = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nMIDsAlone_alt = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each Leader_alt's number of MIDs per year
. gen nMIDsPerYr_alt = nMIDs_alt/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr_alt = nMIDsNoF_alt/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr_alt = nMIDsPrim_alt/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr_alt = nMIDsAlone_alt/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader_alt, sort: egen nForce_alt = total(ForceUS==1)
{txt}
{com}. by Leader_alt, sort: egen nForceNoF_alt = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nForcePrim_alt = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nForceAlone_alt = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr_alt = nForce_alt/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr_alt = nForceNoF_alt/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr_alt = nForcePrim_alt/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr_alt = nForceAlone_alt/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID_alt = nForce_alt/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF_alt = nForceNoF_alt/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim_alt = nForcePrim_alt/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone_alt = nForceAlone_alt/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. order Leader Leader_alt StartDateUS EndDateUS South1 outcome fatality ForceUS LngthMIDUS dispnum3 dispnum4 Party MiltExp MiltOcc TermLength proprec Era lnprevdead pctvetmi
{txt}
{com}. 
. sort Pres1Order StartDateUS
{txt}
{com}.  
. saveold "3-Analysis-Data/15-03-13-USMIDs1.dta", replace
{txt}file 3-Analysis-Data/15-03-13-USMIDs1.dta saved

{com}. outsheet using 3-Analysis-Data/15-03-13-USMIDs1.csv , comma replace
{txt}
{com}. 
{txt}end of do-file

{com}. *Produces "15-03-13-USMIDs1.dta"

. 
. **Truman Southern, GWBush Southern

. do "2-150317-Data-Merge/2-150317-data-merge2.do"
{txt}
{com}. **Code produced in 2015-03-13 by Allan Dafoe and Devin Caughey
. 
. clear
{txt}
{com}. use "3-Analysis-Data/15-03-13-merging.dta"
{txt}
{com}. 
. ** Indicator for Southern origin of Pres1 (under which MID started)
. gen South1 = 0
{txt}
{com}. replace South1 = 1 if inlist(Pres1, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH", "Tyler", "Polk")
{txt}(14 real changes made)

{com}. replace South1 = 1 if inlist(Pres1,  "Taylor", "JohnsonA", "Wilson", "Truman", "JohnsonLB", "Carter", "Clinton", "BushGW")
{txt}(131 real changes made)

{com}. replace South1 = . if Pres1=="" 
{txt}(0 real changes made)

{com}. 
. 
. ** Indicator for Southern origin of Pres2 (who inherited the MID)
. gen South2 = 0
{txt}
{com}. order Pres2 South2
{txt}
{com}. replace South2 = 1 if inlist(Pres2, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH", "Tyler", "Polk")
{txt}(1 real change made)

{com}. replace South2 = 1 if inlist(Pres2, "Taylor", "JohnsonA", "Wilson", "Truman", "JohnsonLB", "Carter", "Clinton", "BushGW")
{txt}(6 real changes made)

{com}. replace South2 = . if Pres2=="" 
{txt}(347 real changes made, 347 to missing)

{com}. 
. 
. ** Start and end dates and length of presidents' terms
. gen TermStartDate = mdy(TermStartMonth, TermStartDay, TermStartYear)
{txt}
{com}. gen TermEndDate = mdy(TermEndMonth, TermEndDay, TermEndYear)  
{txt}(5 missing values generated)

{com}. 
. ** Assigning end of MID data as end of Term for Obama
. replace TermEndDate = mdy(12, 31, 2010) if Pres1=="Obama"
{txt}(5 real changes made)

{com}. replace TermStartDate = mdy(1, 1, 1816) if Pres1 == "Madison"
{txt}(1 real change made)

{com}. 
. format TermEndDate TermStartDate %td
{txt}
{com}. gen TermLength = TermEndDate - TermStartDate + 1 
{txt}
{com}. 
. ** Make Cleveland's term length be the sum of his two terms.
. tab TermLength if Pres1=="Cleveland1" | Pres1=="Cleveland2"

 {txt}TermLength {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
       1462 {c |}{res}         11      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}         11      100.00
{txt}
{com}. replace TermLength = 2* 1462 if Pres1=="Cleveland1" | Pres1=="Cleveland2"
{txt}(11 real changes made)

{com}. 
. order TermStartDate TermEndDate
{txt}
{com}. 
. *** Code to create variable proprec, which measures the proportion of the 
. *** President's term that experienced a recession
. ** daysrec is Days in Recession
. gen proprec = daysrec / TermLength
{txt}
{com}. 
. ** Days into Pres1's term that US involvement in the MID began/ended
. gen StrtDayInTrm1 = StartDateUS - TermStartDate
{txt}
{com}. rename TermStartDate TermStartDate1  
{res}{txt}
{com}. rename TermEndDate TermEndDate1               
{res}{txt}
{com}. 
. gen EndDayInTrm1 = EndDateUS - TermStartDate1
{txt}
{com}.                   
. gen DaysInTrm1 = LngthMIDUS
{txt}
{com}. replace DaysInTrm1 = TermEndDate1 - StartDateUS + 1 if Pres2!=""
{txt}(23 real changes made)

{com}. order StrtDayInTrm1 EndDayInTrm1
{txt}
{com}. 
. ** Indicator for the US being Originator of the dispute
. gen US_Init = orig
{txt}
{com}. 
. ** Indicator for US being the only nation on its side of the MID        
. gen US_alone = 0
{txt}
{com}. replace US_alone = 1 if sidea==1 & numa==1
{txt}(143 real changes made)

{com}. replace US_alone = 1 if sidea==0 & numb==1
{txt}(100 real changes made)

{com}. 
. ** Indicator for US's opponent being the only nation on its side
. gen opp_alone = 0
{txt}
{com}. replace opp_alone = 1 if sidea==1 & numb==1
{txt}(187 real changes made)

{com}. replace opp_alone = 1 if sidea==0 & numa==1
{txt}(151 real changes made)

{com}. 
. ** Indicator for both parties being the only nation on each's side
. gen BothAlone = US_alone*opp_alone
{txt}
{com}. 
. ** Index observations within each president, ordered by the date of US
. ** involvement, dispute number
. sort Pres1 StartDateUS dispnum3 dispnum4
{txt}
{com}. by Pres1: egen int PresOb = seq()
{txt}
{com}. sort StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Indicator for fishing disputes, from Cohen and Weeks
. gen FishDisp = 0
{txt}
{com}. replace FishDisp = 1 if dispnum3==1705 | dispnum3==3222 | dispnum3==2845 | dispnum3==3244 | dispnum3==1803 | dispnum3==1805 | dispnum3==350 | dispnum3==1158 | dispnum3==601 | dispnum3==602 | dispnum3==2952 | dispnum3==2954 | dispnum3==2953 | dispnum3==2958 | dispnum3==2222 | dispnum3==2968 | dispnum3==2967 | dispnum3==3972 | dispnum3==4183 | dispnum3==4174
{txt}(20 real changes made)

{com}. 
. ** Variable for number of opponents of US in MID
. gen nOpps = numb if sidea==1
{txt}(169 missing values generated)

{com}. replace nOpps = numa if sidea==0
{txt}(169 real changes made)

{com}. 
. *** Create placeholder observations for Presidents in whose terms no
. *** MIDs occurred
. set obs `=_N + 1'
{txt}obs was 372, now 373

{com}. replace Pres1 = "Washington" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 1 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(4, 30, 1789) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 373, now 374

{com}. replace Pres1 = "AdamsJ" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 2 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1801) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 374, now 375

{com}. replace Pres1 = "Jefferson" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 3 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1801) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1809) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l 
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 375, now 376

{com}. replace Pres1 = "HarrisonWH" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 9 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1841) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(4, 6, 1841) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 376, now 377

{com}. replace Pres1 = "Taylor" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 12 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 5, 1849) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(7, 10, 1850) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 377, now 378

{com}. replace Pres1 = "Garfield" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 20 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1881) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(9, 20, 1881) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Republican" in l
{txt}(1 real change made)

{com}. 
. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Create simpler version of party for first president
. gen Party1 = Party    
{txt}(3 missing values generated)

{com}. replace Party1 = "Democratic" if Party=="Democratic; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Republican" if Party=="Republican; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Whig" if Party=="Whig; None"
{txt}(2 real changes made)

{com}. replace Party1 = "Democratic-Republican" if  Party=="Democratic-Republican; National Republican"
{txt}(1 real change made)

{com}. encode Party1, generate (Party1Factor)
{txt}
{com}. 
. ** Labels for `outcome'
. label define outcome -1 "US Lose" 0 "Stalemate, Compromise, Released, Unclear, Join war, Missing" 1 "US Win"
{txt}
{com}. 
. label value outcome outcome
{txt}
{com}. 
. 
. ** Indicator for whether the US was an Originator in the dispute
. gen Primary = 0
{txt}
{com}. replace Primary = 1 if orig==1
{txt}(316 real changes made)

{com}. 
. ** Create label for `Order' that includes missing presidents
. label define PresOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 24 "Cleveland" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. gen Pres1Order = Order
{txt}
{com}. drop Order
{txt}
{com}. label values Pres1Order PresOrder 
{txt}
{com}. 
. ** Create cluster variable `Leader' that treats Cleveland's two terms 
. ** as one cluster
. generate Leader = Pres1Order
{txt}
{com}. replace Leader = 22 if Leader==24
{txt}(5 real changes made)

{com}. 
. ** Create label for `Leader' that includes missing presidents, but 
. ** Cleveland is only listed once.
. label define LeaderOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. label values Leader LeaderOrder 
{txt}
{com}. 
. generate Leader2 = .
{txt}(378 missing values generated)

{com}. replace Leader2 = Leader[_n] + 1 if Pres2!=""
{txt}(25 real changes made)

{com}. label values Leader2 LeaderOrder
{txt}
{com}. 
. ** Note: the only difference between `Leader' and `Pres1Order' is that 
. ** the two non-consecutive administrations of Grover Cleveland are 
. ** listed under the same number (22) in `Leader' but as different 
. ** numbers (22 and 24) in `Pres1Order'. 
.  
. ** Previous and next presidents
. gen PresPrev = Pres1Order - 1
{txt}
{com}. label values PresPrev PresOrder
{txt}
{com}. gen PresNext = Pres1Order + 1
{txt}
{com}. label values PresNext PresOrder
{txt}
{com}. replace PresPrev = . if PresPrev==0
{txt}(1 real change made, 1 to missing)

{com}. replace PresNext = . if PresPrev==45
{txt}(0 real changes made)

{com}. 
. sort Pres1Order StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort dispnum3 dispnum4
{txt}
{com}. by dispnum3 dispnum4: egen ObInDispute = seq()
{txt}
{com}. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort Leader StartDateUS dispnum3 dispnum4
{txt}
{com}. by Leader: egen int LeaderOb = seq()
{txt}
{com}. 
. ** Expressing Term Length in Years
. gen TermYrsAdj = TermLeng/365.25
{txt}
{com}. 
. 
. ** Number of MIDs of each Leader in each category
. by Leader, sort: egen nMIDs = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader, sort: egen nMIDsNoF = total(FishDisp==0)
{txt}
{com}. by Leader, sort: egen nMIDsPrim = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nMIDsAlone = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. by Leader, sort: egen nMIDsAloneTarg = total(FishDisp==0 & BothAlone==1 & sidea==0)
{txt}
{com}. by Leader, sort: egen nMIDsAloneInit = total(FishDisp==0 & BothAlone==1 & sidea==1)
{txt}
{com}. 
. ** Each Leader's number of MIDs per year
. gen nMIDsPerYr = nMIDs/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr = nMIDsNoF/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr = nMIDsPrim/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr = nMIDsAlone/TermYrsAdj
{txt}
{com}. gen nMIDsAloneTargPerYr = nMIDsAloneTarg/TermYrsAdj
{txt}
{com}. gen nMIDsAloneInitPerYr = nMIDsAloneInit/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader, sort: egen nForce = total(ForceUS==1)
{txt}
{com}. by Leader, sort: egen nForceNoF = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader, sort: egen nForcePrim = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nForceAlone = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr = nForce/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr = nForceNoF/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr = nForcePrim/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr = nForceAlone/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID = nForce/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF = nForceNoF/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim = nForcePrim/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone = nForceAlone/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. 
. ** Time variables
. gen TermStartDateSq = TermStartDate1^2
{txt}
{com}. gen TermStartDateCu = TermStartDate1^3
{txt}
{com}. gen Era = 1
{txt}
{com}. replace Era = 2 if Leader>=25 & Leader<33
{txt}(55 real changes made)

{com}. replace Era = 3 if Leader>=33
{txt}(245 real changes made)

{com}. label define Era 1 "pre-1897" 2 "1897-1945" 3 "post-1945"
{txt}
{com}. label values Era Era
{txt}
{com}. 
. ** Merge country-year data (this is a subset of Gelpi and 
. ** Feaver's data with one observation per year)
. ** Merging on MID Start Year
. gen year = styear
{txt}(6 missing values generated)

{com}. sort year
{txt}
{com}. merge m:1 year using "1-Original-Data/bigstickcountry-year.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             123
{txt}{col 9}from master{col 30}{res}              71{txt}  (_merge==1)
{col 9}from using{col 30}{res}              52{txt}  (_merge==2)

{col 5}matched{col 30}{res}             307{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}         71       16.51       16.51
{txt}         using only (2) {c |}{res}         52       12.09       28.60
{txt}            matched (3) {c |}{res}        307       71.40      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}        430      100.00
{txt}
{com}. sum year if _merge==1

{txt}    Variable {c |}       Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 56}
{space 8}year {c |}{res}        65    2000.908    5.011621       1993       2010
{txt}
{com}. ** G&F's data doesn't go beyond 1992.
. 
. ** _merge==2 are country-years when there was not a MID.
. drop if _merge==2
{txt}(52 observations deleted)

{com}. drop _merge
{txt}
{com}. 
. 
. sort Pres1Order StartDateUS
{txt}
{com}. 
. replace ObInDispute = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDs = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsPrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForce = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForcePrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. 
. *** Alternative assignment of MIDs to Leader2
. generate alt = .
{txt}(378 missing values generated)

{com}. replace alt = 0 if dispnum3!=.
{txt}(372 real changes made)

{com}. ** Mexican-American War (Tyler and Polk)
. replace alt = 1 if dispnum3==1552
{txt}(1 real change made)

{com}. ** 1958-61 dipute with North Korea (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==2187
{txt}(1 real change made)

{com}. ** Bay of Pigs Invasion (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==40
{txt}(0 real changes made)

{com}. ** 1963-64 dispute with North Korea (Kennedy and JohnsonLB)
. replace alt = 1 if dispnum3==2189
{txt}(1 real change made)

{com}. ** Cambodian Campaign (JohnsonLB and Nixon)
. replace alt = 1 if dispnum3==1806
{txt}(1 real change made)

{com}. ** Invasion of Panama (Reagan and BushGHW)                         
. replace alt = 1 if dispnum3==3901
{txt}(1 real change made)

{com}. ** Yugoslav wars (BushGHW and Clinton)
. replace alt = 1 if dispnum3==3551
{txt}(1 real change made)

{com}. 
. generate Leader_alt = Leader
{txt}
{com}. replace Leader_alt = Leader2 if alt==1
{txt}(6 real changes made)

{com}. label values Leader_alt LeaderOrder
{txt}
{com}. 
. ** Number of MIDs of each Leader_alt in each category
. by Leader_alt, sort: egen nMIDs_alt = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader_alt, sort: egen nMIDsNoF_alt = total(FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nMIDsPrim_alt = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nMIDsAlone_alt = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each Leader_alt's number of MIDs per year
. gen nMIDsPerYr_alt = nMIDs_alt/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr_alt = nMIDsNoF_alt/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr_alt = nMIDsPrim_alt/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr_alt = nMIDsAlone_alt/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader_alt, sort: egen nForce_alt = total(ForceUS==1)
{txt}
{com}. by Leader_alt, sort: egen nForceNoF_alt = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nForcePrim_alt = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nForceAlone_alt = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr_alt = nForce_alt/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr_alt = nForceNoF_alt/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr_alt = nForcePrim_alt/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr_alt = nForceAlone_alt/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID_alt = nForce_alt/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF_alt = nForceNoF_alt/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim_alt = nForcePrim_alt/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone_alt = nForceAlone_alt/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. order Leader Leader_alt StartDateUS EndDateUS South1 outcome fatality ForceUS LngthMIDUS dispnum3 dispnum4 Party MiltExp MiltOcc TermLength proprec Era lnprevdead pctvetmi
{txt}
{com}. 
. sort Pres1Order StartDateUS
{txt}
{com}.  
. saveold "3-Analysis-Data/15-03-13-USMIDs2.dta", replace
{txt}file 3-Analysis-Data/15-03-13-USMIDs2.dta saved

{com}. outsheet using 3-Analysis-Data/15-03-13-USMIDs2.csv , comma replace
{txt}
{com}. 
{txt}end of do-file

{com}. *Produces "15-03-13-USMIDs2.dta"

. 
. **Truman not Southern, GWBush not Southern

. do "2-150317-Data-Merge/2-150317-data-merge3.do"
{txt}
{com}. **Code produced in 2015-03-13 by Allan Dafoe and Devin Caughey
. 
. clear
{txt}
{com}. use "3-Analysis-Data/15-03-13-merging.dta"
{txt}
{com}. 
. ** Indicator for Southern origin of Pres1 (under which MID started)
. gen South1 = 0
{txt}
{com}. replace South1 = 1 if inlist(Pres1, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH")
{txt}(11 real changes made)

{com}. replace South1 = 1 if inlist(Pres1, "Tyler", "Polk", "Taylor", "JohnsonA", "Wilson", "JohnsonLB", "Carter", "Clinton")
{txt}(97 real changes made)

{com}. replace South1 = . if Pres1=="" 
{txt}(0 real changes made)

{com}. 
. 
. ** Indicator for Southern origin of Pres2 (who inherited the MID)
. gen South2 = 0
{txt}
{com}. order Pres2 South2
{txt}
{com}. replace South2 = 1 if inlist(Pres2, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH")
{txt}(0 real changes made)

{com}. replace South2 = 1 if inlist(Pres2, "Tyler", "Polk", "Taylor", "JohnsonA", "Wilson", "JohnsonLB", "Carter", "Clinton")
{txt}(5 real changes made)

{com}. replace South2 = . if Pres2=="" 
{txt}(347 real changes made, 347 to missing)

{com}. 
. 
. ** Start and end dates and length of presidents' terms
. gen TermStartDate = mdy(TermStartMonth, TermStartDay, TermStartYear)
{txt}
{com}. gen TermEndDate = mdy(TermEndMonth, TermEndDay, TermEndYear)  
{txt}(5 missing values generated)

{com}. 
. ** Assigning end of MID data as end of Term for Obama
. replace TermEndDate = mdy(12, 31, 2010) if Pres1=="Obama"
{txt}(5 real changes made)

{com}. replace TermStartDate = mdy(1, 1, 1816) if Pres1 == "Madison"
{txt}(1 real change made)

{com}. 
. format TermEndDate TermStartDate %td
{txt}
{com}. gen TermLength = TermEndDate - TermStartDate + 1 
{txt}
{com}. 
. ** Make Cleveland's term length be the sum of his two terms.
. tab TermLength if Pres1=="Cleveland1" | Pres1=="Cleveland2"

 {txt}TermLength {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
       1462 {c |}{res}         11      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}         11      100.00
{txt}
{com}. replace TermLength = 2* 1462 if Pres1=="Cleveland1" | Pres1=="Cleveland2"
{txt}(11 real changes made)

{com}. 
. order TermStartDate TermEndDate
{txt}
{com}. 
. *** Code to create variable proprec, which measures the proportion of the 
. *** President's term that experienced a recession
. ** daysrec is Days in Recession
. gen proprec = daysrec / TermLength
{txt}
{com}. 
. ** Days into Pres1's term that US involvement in the MID began/ended
. gen StrtDayInTrm1 = StartDateUS - TermStartDate
{txt}
{com}. rename TermStartDate TermStartDate1  
{res}{txt}
{com}. rename TermEndDate TermEndDate1               
{res}{txt}
{com}. 
. gen EndDayInTrm1 = EndDateUS - TermStartDate1
{txt}
{com}.                   
. gen DaysInTrm1 = LngthMIDUS
{txt}
{com}. replace DaysInTrm1 = TermEndDate1 - StartDateUS + 1 if Pres2!=""
{txt}(23 real changes made)

{com}. order StrtDayInTrm1 EndDayInTrm1
{txt}
{com}. 
. ** Indicator for the US being Originator of the dispute
. gen US_Init = orig
{txt}
{com}. 
. ** Indicator for US being the only nation on its side of the MID        
. gen US_alone = 0
{txt}
{com}. replace US_alone = 1 if sidea==1 & numa==1
{txt}(143 real changes made)

{com}. replace US_alone = 1 if sidea==0 & numb==1
{txt}(100 real changes made)

{com}. 
. ** Indicator for US's opponent being the only nation on its side
. gen opp_alone = 0
{txt}
{com}. replace opp_alone = 1 if sidea==1 & numb==1
{txt}(187 real changes made)

{com}. replace opp_alone = 1 if sidea==0 & numa==1
{txt}(151 real changes made)

{com}. 
. ** Indicator for both parties being the only nation on each's side
. gen BothAlone = US_alone*opp_alone
{txt}
{com}. 
. ** Index observations within each president, ordered by the date of US
. ** involvement, dispute number
. sort Pres1 StartDateUS dispnum3 dispnum4
{txt}
{com}. by Pres1: egen int PresOb = seq()
{txt}
{com}. sort StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Indicator for fishing disputes, from Cohen and Weeks
. gen FishDisp = 0
{txt}
{com}. replace FishDisp = 1 if dispnum3==1705 | dispnum3==3222 | dispnum3==2845 | dispnum3==3244 | dispnum3==1803 | dispnum3==1805 | dispnum3==350 | dispnum3==1158 | dispnum3==601 | dispnum3==602 | dispnum3==2952 | dispnum3==2954 | dispnum3==2953 | dispnum3==2958 | dispnum3==2222 | dispnum3==2968 | dispnum3==2967 | dispnum3==3972 | dispnum3==4183 | dispnum3==4174
{txt}(20 real changes made)

{com}. 
. ** Variable for number of opponents of US in MID
. gen nOpps = numb if sidea==1
{txt}(169 missing values generated)

{com}. replace nOpps = numa if sidea==0
{txt}(169 real changes made)

{com}. 
. *** Create placeholder observations for Presidents in whose terms no
. *** MIDs occurred
. set obs `=_N + 1'
{txt}obs was 372, now 373

{com}. replace Pres1 = "Washington" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 1 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(4, 30, 1789) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 373, now 374

{com}. replace Pres1 = "AdamsJ" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 2 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1801) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 374, now 375

{com}. replace Pres1 = "Jefferson" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 3 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1801) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1809) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l 
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 375, now 376

{com}. replace Pres1 = "HarrisonWH" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 9 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1841) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(4, 6, 1841) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 376, now 377

{com}. replace Pres1 = "Taylor" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 12 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 5, 1849) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(7, 10, 1850) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 377, now 378

{com}. replace Pres1 = "Garfield" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 20 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1881) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(9, 20, 1881) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Republican" in l
{txt}(1 real change made)

{com}. 
. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Create simpler version of party for first president
. gen Party1 = Party    
{txt}(3 missing values generated)

{com}. replace Party1 = "Democratic" if Party=="Democratic; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Republican" if Party=="Republican; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Whig" if Party=="Whig; None"
{txt}(2 real changes made)

{com}. replace Party1 = "Democratic-Republican" if  Party=="Democratic-Republican; National Republican"
{txt}(1 real change made)

{com}. encode Party1, generate (Party1Factor)
{txt}
{com}. 
. ** Labels for `outcome'
. label define outcome -1 "US Lose" 0 "Stalemate, Compromise, Released, Unclear, Join war, Missing" 1 "US Win"
{txt}
{com}. 
. label value outcome outcome
{txt}
{com}. 
. 
. ** Indicator for whether the US was an Originator in the dispute
. gen Primary = 0
{txt}
{com}. replace Primary = 1 if orig==1
{txt}(316 real changes made)

{com}. 
. ** Create label for `Order' that includes missing presidents
. label define PresOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 24 "Cleveland" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. gen Pres1Order = Order
{txt}
{com}. drop Order
{txt}
{com}. label values Pres1Order PresOrder 
{txt}
{com}. 
. ** Create cluster variable `Leader' that treats Cleveland's two terms 
. ** as one cluster
. generate Leader = Pres1Order
{txt}
{com}. replace Leader = 22 if Leader==24
{txt}(5 real changes made)

{com}. 
. ** Create label for `Leader' that includes missing presidents, but 
. ** Cleveland is only listed once.
. label define LeaderOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. label values Leader LeaderOrder 
{txt}
{com}. 
. generate Leader2 = .
{txt}(378 missing values generated)

{com}. replace Leader2 = Leader[_n] + 1 if Pres2!=""
{txt}(25 real changes made)

{com}. label values Leader2 LeaderOrder
{txt}
{com}. 
. ** Note: the only difference between `Leader' and `Pres1Order' is that 
. ** the two non-consecutive administrations of Grover Cleveland are 
. ** listed under the same number (22) in `Leader' but as different 
. ** numbers (22 and 24) in `Pres1Order'. 
.  
. ** Previous and next presidents
. gen PresPrev = Pres1Order - 1
{txt}
{com}. label values PresPrev PresOrder
{txt}
{com}. gen PresNext = Pres1Order + 1
{txt}
{com}. label values PresNext PresOrder
{txt}
{com}. replace PresPrev = . if PresPrev==0
{txt}(1 real change made, 1 to missing)

{com}. replace PresNext = . if PresPrev==45
{txt}(0 real changes made)

{com}. 
. sort Pres1Order StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort dispnum3 dispnum4
{txt}
{com}. by dispnum3 dispnum4: egen ObInDispute = seq()
{txt}
{com}. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort Leader StartDateUS dispnum3 dispnum4
{txt}
{com}. by Leader: egen int LeaderOb = seq()
{txt}
{com}. 
. ** Expressing Term Length in Years
. gen TermYrsAdj = TermLeng/365.25
{txt}
{com}. 
. 
. ** Number of MIDs of each Leader in each category
. by Leader, sort: egen nMIDs = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader, sort: egen nMIDsNoF = total(FishDisp==0)
{txt}
{com}. by Leader, sort: egen nMIDsPrim = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nMIDsAlone = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. by Leader, sort: egen nMIDsAloneTarg = total(FishDisp==0 & BothAlone==1 & sidea==0)
{txt}
{com}. by Leader, sort: egen nMIDsAloneInit = total(FishDisp==0 & BothAlone==1 & sidea==1)
{txt}
{com}. 
. ** Each Leader's number of MIDs per year
. gen nMIDsPerYr = nMIDs/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr = nMIDsNoF/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr = nMIDsPrim/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr = nMIDsAlone/TermYrsAdj
{txt}
{com}. gen nMIDsAloneTargPerYr = nMIDsAloneTarg/TermYrsAdj
{txt}
{com}. gen nMIDsAloneInitPerYr = nMIDsAloneInit/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader, sort: egen nForce = total(ForceUS==1)
{txt}
{com}. by Leader, sort: egen nForceNoF = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader, sort: egen nForcePrim = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nForceAlone = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr = nForce/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr = nForceNoF/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr = nForcePrim/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr = nForceAlone/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID = nForce/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF = nForceNoF/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim = nForcePrim/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone = nForceAlone/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. 
. ** Time variables
. gen TermStartDateSq = TermStartDate1^2
{txt}
{com}. gen TermStartDateCu = TermStartDate1^3
{txt}
{com}. gen Era = 1
{txt}
{com}. replace Era = 2 if Leader>=25 & Leader<33
{txt}(55 real changes made)

{com}. replace Era = 3 if Leader>=33
{txt}(245 real changes made)

{com}. label define Era 1 "pre-1897" 2 "1897-1945" 3 "post-1945"
{txt}
{com}. label values Era Era
{txt}
{com}. 
. ** Merge country-year data (this is a subset of Gelpi and 
. ** Feaver's data with one observation per year)
. ** Merging on MID Start Year
. gen year = styear
{txt}(6 missing values generated)

{com}. sort year
{txt}
{com}. merge m:1 year using "1-Original-Data/bigstickcountry-year.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             123
{txt}{col 9}from master{col 30}{res}              71{txt}  (_merge==1)
{col 9}from using{col 30}{res}              52{txt}  (_merge==2)

{col 5}matched{col 30}{res}             307{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}         71       16.51       16.51
{txt}         using only (2) {c |}{res}         52       12.09       28.60
{txt}            matched (3) {c |}{res}        307       71.40      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}        430      100.00
{txt}
{com}. sum year if _merge==1

{txt}    Variable {c |}       Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 56}
{space 8}year {c |}{res}        65    2000.908    5.011621       1993       2010
{txt}
{com}. ** G&F's data doesn't go beyond 1992.
. 
. ** _merge==2 are country-years when there was not a MID.
. drop if _merge==2
{txt}(52 observations deleted)

{com}. drop _merge
{txt}
{com}. 
. 
. sort Pres1Order StartDateUS
{txt}
{com}. 
. replace ObInDispute = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDs = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsPrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForce = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForcePrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. 
. *** Alternative assignment of MIDs to Leader2
. generate alt = .
{txt}(378 missing values generated)

{com}. replace alt = 0 if dispnum3!=.
{txt}(372 real changes made)

{com}. ** Mexican-American War (Tyler and Polk)
. replace alt = 1 if dispnum3==1552
{txt}(1 real change made)

{com}. ** 1958-61 dipute with North Korea (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==2187
{txt}(1 real change made)

{com}. ** Bay of Pigs Invasion (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==40
{txt}(0 real changes made)

{com}. ** 1963-64 dispute with North Korea (Kennedy and JohnsonLB)
. replace alt = 1 if dispnum3==2189
{txt}(1 real change made)

{com}. ** Cambodian Campaign (JohnsonLB and Nixon)
. replace alt = 1 if dispnum3==1806
{txt}(1 real change made)

{com}. ** Invasion of Panama (Reagan and BushGHW)                         
. replace alt = 1 if dispnum3==3901
{txt}(1 real change made)

{com}. ** Yugoslav wars (BushGHW and Clinton)
. replace alt = 1 if dispnum3==3551
{txt}(1 real change made)

{com}. 
. generate Leader_alt = Leader
{txt}
{com}. replace Leader_alt = Leader2 if alt==1
{txt}(6 real changes made)

{com}. label values Leader_alt LeaderOrder
{txt}
{com}. 
. ** Number of MIDs of each Leader_alt in each category
. by Leader_alt, sort: egen nMIDs_alt = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader_alt, sort: egen nMIDsNoF_alt = total(FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nMIDsPrim_alt = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nMIDsAlone_alt = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each Leader_alt's number of MIDs per year
. gen nMIDsPerYr_alt = nMIDs_alt/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr_alt = nMIDsNoF_alt/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr_alt = nMIDsPrim_alt/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr_alt = nMIDsAlone_alt/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader_alt, sort: egen nForce_alt = total(ForceUS==1)
{txt}
{com}. by Leader_alt, sort: egen nForceNoF_alt = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nForcePrim_alt = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nForceAlone_alt = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr_alt = nForce_alt/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr_alt = nForceNoF_alt/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr_alt = nForcePrim_alt/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr_alt = nForceAlone_alt/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID_alt = nForce_alt/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF_alt = nForceNoF_alt/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim_alt = nForcePrim_alt/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone_alt = nForceAlone_alt/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. order Leader Leader_alt StartDateUS EndDateUS South1 outcome fatality ForceUS LngthMIDUS dispnum3 dispnum4 Party MiltExp MiltOcc TermLength proprec Era lnprevdead pctvetmi
{txt}
{com}. 
. sort Pres1Order StartDateUS
{txt}
{com}.  
. saveold "3-Analysis-Data/15-03-13-USMIDs3.dta", replace
{txt}file 3-Analysis-Data/15-03-13-USMIDs3.dta saved

{com}. outsheet using 3-Analysis-Data/15-03-13-USMIDs3.csv , comma replace
{txt}
{com}. 
{txt}end of do-file

{com}. *Produces "15-03-13-USMIDs3.dta"

. 
. **Truman Southern, GWBush not Southern

. do "2-150317-Data-Merge/2-150317-data-merge4.do"
{txt}
{com}. **Code produced in 2015-03-13 by Allan Dafoe and Devin Caughey
. 
. clear
{txt}
{com}. use "3-Analysis-Data/15-03-13-merging.dta"
{txt}
{com}. 
. ** Indicator for Southern origin of Pres1 (under which MID started)
. gen South1 = 0
{txt}
{com}. replace South1 = 1 if inlist(Pres1, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH")
{txt}(11 real changes made)

{com}. replace South1 = 1 if inlist(Pres1, "Tyler", "Polk", "Taylor", "JohnsonA", "Wilson", "Truman", "JohnsonLB", "Carter", "Clinton")
{txt}(107 real changes made)

{com}. replace South1 = . if Pres1=="" 
{txt}(0 real changes made)

{com}. 
. 
. ** Indicator for Southern origin of Pres2 (who inherited the MID)
. gen South2 = 0
{txt}
{com}. order Pres2 South2
{txt}
{com}. replace South2 = 1 if inlist(Pres2, "Washington", "Jefferson", "Madison", "Monroe", "Jackson", "HarrisonWH")
{txt}(0 real changes made)

{com}. replace South2 = 1 if inlist(Pres2, "Tyler", "Polk", "Taylor", "JohnsonA", "Wilson", "Truman", "JohnsonLB", "Carter", "Clinton")
{txt}(6 real changes made)

{com}. replace South2 = . if Pres2=="" 
{txt}(347 real changes made, 347 to missing)

{com}. 
. 
. ** Start and end dates and length of presidents' terms
. gen TermStartDate = mdy(TermStartMonth, TermStartDay, TermStartYear)
{txt}
{com}. gen TermEndDate = mdy(TermEndMonth, TermEndDay, TermEndYear)  
{txt}(5 missing values generated)

{com}. 
. ** Assigning end of MID data as end of Term for Obama
. replace TermEndDate = mdy(12, 31, 2010) if Pres1=="Obama"
{txt}(5 real changes made)

{com}. replace TermStartDate = mdy(1, 1, 1816) if Pres1 == "Madison"
{txt}(1 real change made)

{com}. 
. format TermEndDate TermStartDate %td
{txt}
{com}. gen TermLength = TermEndDate - TermStartDate + 1 
{txt}
{com}. 
. ** Make Cleveland's term length be the sum of his two terms.
. tab TermLength if Pres1=="Cleveland1" | Pres1=="Cleveland2"

 {txt}TermLength {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
       1462 {c |}{res}         11      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}         11      100.00
{txt}
{com}. replace TermLength = 2* 1462 if Pres1=="Cleveland1" | Pres1=="Cleveland2"
{txt}(11 real changes made)

{com}. 
. order TermStartDate TermEndDate
{txt}
{com}. 
. *** Code to create variable proprec, which measures the proportion of the 
. *** President's term that experienced a recession
. ** daysrec is Days in Recession
. gen proprec = daysrec / TermLength
{txt}
{com}. 
. ** Days into Pres1's term that US involvement in the MID began/ended
. gen StrtDayInTrm1 = StartDateUS - TermStartDate
{txt}
{com}. rename TermStartDate TermStartDate1  
{res}{txt}
{com}. rename TermEndDate TermEndDate1               
{res}{txt}
{com}. 
. gen EndDayInTrm1 = EndDateUS - TermStartDate1
{txt}
{com}.                   
. gen DaysInTrm1 = LngthMIDUS
{txt}
{com}. replace DaysInTrm1 = TermEndDate1 - StartDateUS + 1 if Pres2!=""
{txt}(23 real changes made)

{com}. order StrtDayInTrm1 EndDayInTrm1
{txt}
{com}. 
. ** Indicator for the US being Originator of the dispute
. gen US_Init = orig
{txt}
{com}. 
. ** Indicator for US being the only nation on its side of the MID        
. gen US_alone = 0
{txt}
{com}. replace US_alone = 1 if sidea==1 & numa==1
{txt}(143 real changes made)

{com}. replace US_alone = 1 if sidea==0 & numb==1
{txt}(100 real changes made)

{com}. 
. ** Indicator for US's opponent being the only nation on its side
. gen opp_alone = 0
{txt}
{com}. replace opp_alone = 1 if sidea==1 & numb==1
{txt}(187 real changes made)

{com}. replace opp_alone = 1 if sidea==0 & numa==1
{txt}(151 real changes made)

{com}. 
. ** Indicator for both parties being the only nation on each's side
. gen BothAlone = US_alone*opp_alone
{txt}
{com}. 
. ** Index observations within each president, ordered by the date of US
. ** involvement, dispute number
. sort Pres1 StartDateUS dispnum3 dispnum4
{txt}
{com}. by Pres1: egen int PresOb = seq()
{txt}
{com}. sort StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Indicator for fishing disputes, from Cohen and Weeks
. gen FishDisp = 0
{txt}
{com}. replace FishDisp = 1 if dispnum3==1705 | dispnum3==3222 | dispnum3==2845 | dispnum3==3244 | dispnum3==1803 | dispnum3==1805 | dispnum3==350 | dispnum3==1158 | dispnum3==601 | dispnum3==602 | dispnum3==2952 | dispnum3==2954 | dispnum3==2953 | dispnum3==2958 | dispnum3==2222 | dispnum3==2968 | dispnum3==2967 | dispnum3==3972 | dispnum3==4183 | dispnum3==4174
{txt}(20 real changes made)

{com}. 
. ** Variable for number of opponents of US in MID
. gen nOpps = numb if sidea==1
{txt}(169 missing values generated)

{com}. replace nOpps = numa if sidea==0
{txt}(169 real changes made)

{com}. 
. *** Create placeholder observations for Presidents in whose terms no
. *** MIDs occurred
. set obs `=_N + 1'
{txt}obs was 372, now 373

{com}. replace Pres1 = "Washington" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 1 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(4, 30, 1789) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 373, now 374

{com}. replace Pres1 = "AdamsJ" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 2 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1797) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1801) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 374, now 375

{com}. replace Pres1 = "Jefferson" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 3 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1801) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(3, 4, 1809) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l 
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 375, now 376

{com}. replace Pres1 = "HarrisonWH" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 9 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1841) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(4, 6, 1841) in l 
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 376, now 377

{com}. replace Pres1 = "Taylor" in l
{txt}(1 real change made)

{com}. replace South1 = 1 in l
{txt}(1 real change made)

{com}. replace Order = 12 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 5, 1849) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(7, 10, 1850) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Whig" in l
{txt}(1 real change made)

{com}. set obs `=_N + 1'
{txt}obs was 377, now 378

{com}. replace Pres1 = "Garfield" in l
{txt}(1 real change made)

{com}. replace South1 = 0 in l
{txt}(1 real change made)

{com}. replace Order = 20 in l
{txt}(1 real change made)

{com}. replace TermStartDate = mdy(3, 4, 1881) in l
{txt}(1 real change made)

{com}. replace TermEndDate = mdy(9, 20, 1881) in l
{txt}(1 real change made)

{com}. replace TermLength = TermEndDate - TermStartDate + 1 in l
{txt}(1 real change made)

{com}. replace Party = "Republican" in l
{txt}(1 real change made)

{com}. 
. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. ** Create simpler version of party for first president
. gen Party1 = Party    
{txt}(3 missing values generated)

{com}. replace Party1 = "Democratic" if Party=="Democratic; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Republican" if Party=="Republican; National Union"
{txt}(5 real changes made)

{com}. replace Party1 = "Whig" if Party=="Whig; None"
{txt}(2 real changes made)

{com}. replace Party1 = "Democratic-Republican" if  Party=="Democratic-Republican; National Republican"
{txt}(1 real change made)

{com}. encode Party1, generate (Party1Factor)
{txt}
{com}. 
. ** Labels for `outcome'
. label define outcome -1 "US Lose" 0 "Stalemate, Compromise, Released, Unclear, Join war, Missing" 1 "US Win"
{txt}
{com}. 
. label value outcome outcome
{txt}
{com}. 
. 
. ** Indicator for whether the US was an Originator in the dispute
. gen Primary = 0
{txt}
{com}. replace Primary = 1 if orig==1
{txt}(316 real changes made)

{com}. 
. ** Create label for `Order' that includes missing presidents
. label define PresOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 24 "Cleveland" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. gen Pres1Order = Order
{txt}
{com}. drop Order
{txt}
{com}. label values Pres1Order PresOrder 
{txt}
{com}. 
. ** Create cluster variable `Leader' that treats Cleveland's two terms 
. ** as one cluster
. generate Leader = Pres1Order
{txt}
{com}. replace Leader = 22 if Leader==24
{txt}(5 real changes made)

{com}. 
. ** Create label for `Leader' that includes missing presidents, but 
. ** Cleveland is only listed once.
. label define LeaderOrder 1 "Washington" 2 "AdamsJ" 3 "Jefferson" 4 "Madison" 5 "Monroe" 6 "AdamsJQ" 7 "Jackson" 8 "Van_Buren" 9 "HarrisonWH" 10 "Tyler" 11 "Polk" 12 "Taylor" 13 "Fillmore" 14 "Pierce" 15 "Buchanan" 16 "Lincoln" 17 "JohnsonA" 18 "Grant" 19 "Hayes" 20 "Garfield" 21 "Arthur" 22 "Cleveland" 23 "HarrisonB" 25 "McKinley" 26 "RooseveltT" 27 "Taft" 28 "Wilson" 29 "Harding" 30 "Coolidge" 31 "Hoover" 32 "RooseveltFD" 33 "Truman" 34 "Eisenhower" 35 "Kennedy" 36 "JohnsonLB" 37 "Nixon" 38 "Ford" 39 "Carter" 40 "Reagan" 41 "BushGHW" 42 "Clinton" 43 "BushGW" 44 "Obama"
{txt}
{com}. 
. label values Leader LeaderOrder 
{txt}
{com}. 
. generate Leader2 = .
{txt}(378 missing values generated)

{com}. replace Leader2 = Leader[_n] + 1 if Pres2!=""
{txt}(25 real changes made)

{com}. label values Leader2 LeaderOrder
{txt}
{com}. 
. ** Note: the only difference between `Leader' and `Pres1Order' is that 
. ** the two non-consecutive administrations of Grover Cleveland are 
. ** listed under the same number (22) in `Leader' but as different 
. ** numbers (22 and 24) in `Pres1Order'. 
.  
. ** Previous and next presidents
. gen PresPrev = Pres1Order - 1
{txt}
{com}. label values PresPrev PresOrder
{txt}
{com}. gen PresNext = Pres1Order + 1
{txt}
{com}. label values PresNext PresOrder
{txt}
{com}. replace PresPrev = . if PresPrev==0
{txt}(1 real change made, 1 to missing)

{com}. replace PresNext = . if PresPrev==45
{txt}(0 real changes made)

{com}. 
. sort Pres1Order StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort dispnum3 dispnum4
{txt}
{com}. by dispnum3 dispnum4: egen ObInDispute = seq()
{txt}
{com}. sort TermStartDate StartDateUS dispnum3 dispnum4
{txt}
{com}. 
. sort Leader StartDateUS dispnum3 dispnum4
{txt}
{com}. by Leader: egen int LeaderOb = seq()
{txt}
{com}. 
. ** Expressing Term Length in Years
. gen TermYrsAdj = TermLeng/365.25
{txt}
{com}. 
. 
. ** Number of MIDs of each Leader in each category
. by Leader, sort: egen nMIDs = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader, sort: egen nMIDsNoF = total(FishDisp==0)
{txt}
{com}. by Leader, sort: egen nMIDsPrim = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nMIDsAlone = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. by Leader, sort: egen nMIDsAloneTarg = total(FishDisp==0 & BothAlone==1 & sidea==0)
{txt}
{com}. by Leader, sort: egen nMIDsAloneInit = total(FishDisp==0 & BothAlone==1 & sidea==1)
{txt}
{com}. 
. ** Each Leader's number of MIDs per year
. gen nMIDsPerYr = nMIDs/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr = nMIDsNoF/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr = nMIDsPrim/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr = nMIDsAlone/TermYrsAdj
{txt}
{com}. gen nMIDsAloneTargPerYr = nMIDsAloneTarg/TermYrsAdj
{txt}
{com}. gen nMIDsAloneInitPerYr = nMIDsAloneInit/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader, sort: egen nForce = total(ForceUS==1)
{txt}
{com}. by Leader, sort: egen nForceNoF = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader, sort: egen nForcePrim = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader, sort: egen nForceAlone = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr = nForce/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr = nForceNoF/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr = nForcePrim/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr = nForceAlone/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID = nForce/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF = nForceNoF/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim = nForcePrim/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone = nForceAlone/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. 
. ** Time variables
. gen TermStartDateSq = TermStartDate1^2
{txt}
{com}. gen TermStartDateCu = TermStartDate1^3
{txt}
{com}. gen Era = 1
{txt}
{com}. replace Era = 2 if Leader>=25 & Leader<33
{txt}(55 real changes made)

{com}. replace Era = 3 if Leader>=33
{txt}(245 real changes made)

{com}. label define Era 1 "pre-1897" 2 "1897-1945" 3 "post-1945"
{txt}
{com}. label values Era Era
{txt}
{com}. 
. ** Merge country-year data (this is a subset of Gelpi and 
. ** Feaver's data with one observation per year)
. ** Merging on MID Start Year
. gen year = styear
{txt}(6 missing values generated)

{com}. sort year
{txt}
{com}. merge m:1 year using "1-Original-Data/bigstickcountry-year.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             123
{txt}{col 9}from master{col 30}{res}              71{txt}  (_merge==1)
{col 9}from using{col 30}{res}              52{txt}  (_merge==2)

{col 5}matched{col 30}{res}             307{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}         71       16.51       16.51
{txt}         using only (2) {c |}{res}         52       12.09       28.60
{txt}            matched (3) {c |}{res}        307       71.40      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}        430      100.00
{txt}
{com}. sum year if _merge==1

{txt}    Variable {c |}       Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 56}
{space 8}year {c |}{res}        65    2000.908    5.011621       1993       2010
{txt}
{com}. ** G&F's data doesn't go beyond 1992.
. 
. ** _merge==2 are country-years when there was not a MID.
. drop if _merge==2
{txt}(52 observations deleted)

{com}. drop _merge
{txt}
{com}. 
. 
. sort Pres1Order StartDateUS
{txt}
{com}. 
. replace ObInDispute = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDs = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsPrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nMIDsAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForce = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceNoF = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForcePrim = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. replace nForceAlone = . if Leader<=3 | Leader>44
{txt}(3 real changes made, 3 to missing)

{com}. 
. *** Alternative assignment of MIDs to Leader2
. generate alt = .
{txt}(378 missing values generated)

{com}. replace alt = 0 if dispnum3!=.
{txt}(372 real changes made)

{com}. ** Mexican-American War (Tyler and Polk)
. replace alt = 1 if dispnum3==1552
{txt}(1 real change made)

{com}. ** 1958-61 dipute with North Korea (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==2187
{txt}(1 real change made)

{com}. ** Bay of Pigs Invasion (Eisenhower and Kennedy)
. replace alt = 1 if dispnum3==40
{txt}(0 real changes made)

{com}. ** 1963-64 dispute with North Korea (Kennedy and JohnsonLB)
. replace alt = 1 if dispnum3==2189
{txt}(1 real change made)

{com}. ** Cambodian Campaign (JohnsonLB and Nixon)
. replace alt = 1 if dispnum3==1806
{txt}(1 real change made)

{com}. ** Invasion of Panama (Reagan and BushGHW)                         
. replace alt = 1 if dispnum3==3901
{txt}(1 real change made)

{com}. ** Yugoslav wars (BushGHW and Clinton)
. replace alt = 1 if dispnum3==3551
{txt}(1 real change made)

{com}. 
. generate Leader_alt = Leader
{txt}
{com}. replace Leader_alt = Leader2 if alt==1
{txt}(6 real changes made)

{com}. label values Leader_alt LeaderOrder
{txt}
{com}. 
. ** Number of MIDs of each Leader_alt in each category
. by Leader_alt, sort: egen nMIDs_alt = total(FishDisp==0 | FishDisp==1)
{txt}
{com}. by Leader_alt, sort: egen nMIDsNoF_alt = total(FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nMIDsPrim_alt = total(FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nMIDsAlone_alt = total(FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each Leader_alt's number of MIDs per year
. gen nMIDsPerYr_alt = nMIDs_alt/TermYrsAdj
{txt}
{com}. gen nMIDsNoFPerYr_alt = nMIDsNoF_alt/TermYrsAdj
{txt}
{com}. gen nMIDsPrimPerYr_alt = nMIDsPrim_alt/TermYrsAdj
{txt}
{com}. gen nMIDsAlonePerYr_alt = nMIDsAlone_alt/TermYrsAdj
{txt}
{com}. 
. ** Each leader's # of MIDs in each category in which the US used Force
. by Leader_alt, sort: egen nForce_alt = total(ForceUS==1)
{txt}
{com}. by Leader_alt, sort: egen nForceNoF_alt = total(ForceUS==1 & FishDisp==0)
{txt}
{com}. by Leader_alt, sort: egen nForcePrim_alt = total(ForceUS==1 & FishDisp==0 & Primary==1) 
{txt}
{com}. by Leader_alt, sort: egen nForceAlone_alt = total(ForceUS==1 & FishDisp==0 & BothAlone==1)
{txt}
{com}. 
. ** Each leader's uses of force per year in each category
. gen nForcePerYr_alt = nForce_alt/TermYrsAdj
{txt}
{com}. gen nForceNoFPerYr_alt = nForceNoF_alt/TermYrsAdj
{txt}
{com}. gen nForcePrimPerYr_alt = nForcePrim_alt/TermYrsAdj
{txt}
{com}. gen nForceAlonePerYr_alt = nForceAlone_alt/TermYrsAdj 
{txt}
{com}. 
. ** Each leader's uses of force per MID in each category
. gen nForcePerMID_alt = nForce_alt/nMIDs
{txt}(6 missing values generated)

{com}. gen nForcePerMIDNoF_alt = nForceNoF_alt/nMIDsNoF
{txt}(6 missing values generated)

{com}. gen nForcePerMIDPrim_alt = nForcePrim_alt/nMIDsPrim
{txt}(6 missing values generated)

{com}. gen nForcePerMIDAlone_alt = nForceAlone_alt/nMIDsAlone
{txt}(9 missing values generated)

{com}. 
. order Leader Leader_alt StartDateUS EndDateUS South1 outcome fatality ForceUS LngthMIDUS dispnum3 dispnum4 Party MiltExp MiltOcc TermLength proprec Era lnprevdead pctvetmi
{txt}
{com}. 
. sort Pres1Order StartDateUS
{txt}
{com}.  
. saveold "3-Analysis-Data/15-03-13-USMIDs4.dta", replace
{txt}file 3-Analysis-Data/15-03-13-USMIDs4.dta saved

{com}. outsheet using 3-Analysis-Data/15-03-13-USMIDs4.csv , comma replace
{txt}
{com}. 
{txt}end of do-file

{com}. *Produces "15-03-13-USMIDs4.dta"

. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}/Users/Allan/Dropbox/1Papers/1Reputation/Honor-Culture-War/2012-05/Replication-Final/2-150317-Data-Merge/2-150317-data-merge-log.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}30 Jun 2015, 16:02:42
{txt}{.-}
{smcl}
{txt}{sf}{ul off}